import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { Base } from "@/entities.base/base.entity";
import { Customer } from "../customer.entity";

@Entity({ comment: '客户储值卡表', name: 'basis_customer_stored_value_card' })
export class CustomerStoredValueCard extends Base {

    /** 卡号 */
    @Column({
        comment: '卡号',
        length: 50,
        unique: true, // 卡号唯一
    })
    cardNumber: string;

    /** 卡片名称 */
    @Column({
        comment: '卡片名称',
        length: 100,
    })
    cardName: string;

    /** 充值金额 */
    @Column({
        comment: '充值金额',
        type: 'decimal',
        precision: 10,
        scale: 2,
        default: 0,
    })
    rechargeAmount: number;

    /** 赠送金额 */
    @Column({
        comment: '赠送金额',
        type: 'decimal',
        precision: 10,
        scale: 2,
        default: 0,
    })
    giftAmount: number;

    /** 赠送积分 */
    @Column({
        comment: '赠送积分',
        type: 'decimal',
        precision: 10,
        scale: 2,
        default: 0,
    })
    giftPoints: number;

    /** 当前余额 */
    @Column({
        comment: '当前余额',
        type: 'decimal',
        precision: 10,
        scale: 2,
        default: 0,
    })
    currentBalance: number;

    /** 有效期开始时间 */
    @Column({
        comment: '有效期开始时间',
        type: 'date',
        nullable: true,
    })
    validFrom?: Date;

    /** 有效期结束时间 */
    @Column({
        comment: '有效期结束时间',
        type: 'date',
        nullable: true,
    })
    validTo?: Date;

    /** 备注 */
    @Column({
        type: 'text',
        comment: '备注',
        nullable: true,
    })
    remark?: string;

    /** 关联的客户ID */
    @Column({
        comment: '客户ID',
        nullable: false,
    })
    customerId: string;

    /** 关联客户 - 多对一关系 */
    @ManyToOne(() => Customer, { onDelete: 'CASCADE' })
    @JoinColumn({ name: 'customerId' })
    customer: Customer;
} 